﻿using System.Collections;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.StreetEvent;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class CompareTroopHeroCount : FlowControlNode
    {
        [RequiredField]
        public BBParameter<int> troopIndex;
        public BBParameter<int> count;
        public BBParameter<TaskCounterMode> mode = TaskCounterMode.EqualOrGreater;

        protected override void RegisterPorts()
        {
            var caseTrue = AddFlowOutput("True");
            var caseFalse = AddFlowOutput("False");
            AddFlowInput("In", (f) =>
            {
                int troopHeroCount = BlueprintUtils.GetTroopHeroCount(troopIndex.value);
                bool isTrue = false;
                switch (mode.value)
                {
                    case TaskCounterMode.Equal:
                        {
                            isTrue = troopHeroCount == count.value;
                        }
                        break;
                    case TaskCounterMode.Greater:
                        {
                            isTrue = troopHeroCount > count.value;
                        }
                        break;
                    case TaskCounterMode.Less:
                        {
                            isTrue = troopHeroCount < count.value;
                        }
                        break;
                    case TaskCounterMode.EqualOrGreater:
                        {
                            isTrue = troopHeroCount >= count.value;
                        }
                        break;
                    case TaskCounterMode.EqualOrLess:
                        {
                            isTrue = troopHeroCount <= count.value;
                        }
                        break;
                }
                if (isTrue)
                {
                    f.Call(caseTrue);
                }
                else
                {
                    f.Call(caseFalse);
                }
                
            });

        }
    }
}